package com.ccut.xunfeiSpringboot.controller;

import com.ccut.xunfeiSpringboot.common.AjaxResult;

import com.ccut.xunfeiSpringboot.dto.AnalyseResumeDTO;
import com.ccut.xunfeiSpringboot.dto.ChatRequest;
import com.ccut.xunfeiSpringboot.entity.PositionInformation;
import com.ccut.xunfeiSpringboot.entity.RecommendCareers;
import com.ccut.xunfeiSpringboot.service.BaseService;
import com.ccut.xunfeiSpringboot.service.JobService;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/job")
@Slf4j
public class JobController {

    @Autowired
    private JobService jobService;

    @GetMapping("/selected")
    public AjaxResult selected() {
        return AjaxResult.success(jobService.getSelectedJobs());
    }

    @DeleteMapping("/removeJob")
    public AjaxResult remove(@RequestBody Map<String, Integer> payload) {
        Integer id = payload.get("id");
        jobService.removeJobById(id);
        return AjaxResult.success();
    }

    @PostMapping("/addJob")
    public void add(@RequestBody PositionInformation job,HttpServletResponse response) throws Exception {
        jobService.addJob(job,response);
    }

    @GetMapping("/isRecommended")
    public AjaxResult isRecommended(@RequestParam("userId") Long userId) {
        return AjaxResult.success(jobService.isRecommended(userId));
    }

    @GetMapping("/recommend")
    public void recommendJobs(@RequestParam("userId") Integer userId, HttpServletResponse response) throws Exception {
        jobService.recommendJobs(userId,response);
    }

    @GetMapping("/getRecommendedCareers")
    public AjaxResult getRecommendedCareers(@RequestParam("userId") Integer userId){
        List<RecommendCareers> recommendJobs = jobService.getRecommendedCareers(userId);
        return AjaxResult.success(recommendJobs);
    }

    @DeleteMapping("/removeRecommendedCareer")
    public AjaxResult removeRecommendedCareer(@RequestBody Map<String, Long> payload){
        Long id = payload.get("id");
        jobService.removeRecommendedCarreeer(id);
        return AjaxResult.success();
    }

    @GetMapping("/searchRecommendedJobs")
    public void getRecommendedJobs(@RequestParam("userId") Integer userId, HttpServletResponse response) throws Exception {
        jobService.searchRecommendedJobs(userId,response);
    }

    @GetMapping("/changeRecommendedJob")
    public void changeJob(@RequestParam("userId") Integer userId,HttpServletResponse response) throws Exception {
        jobService.changeJob(userId,response);
    }

    @PostMapping("/addRecommendedCareer")
    public void addRecommendedJob(@RequestBody RecommendCareers recommendCareer, HttpServletResponse httpServletResponse) throws Exception {
        jobService.addRecommendedCareer(recommendCareer,httpServletResponse);
    }

    @GetMapping("/changeRecommendedCareer")
    public void changeRecommendedCareer(@RequestParam("userId") Integer userId,HttpServletResponse response) throws Exception {
        jobService.changeRecommendedCareer(userId,response);
    }

    @GetMapping("/getInterviewedJobs")
    public AjaxResult getRecommendedJobs(@RequestParam("userId") Integer userId){
        List<PositionInformation> recommendJobs = jobService.getInterviewedJobs(userId);
        return AjaxResult.success(recommendJobs);
    }

    @GetMapping("/getNotInterviewedJobs")
    public AjaxResult getNotInterviewedJobs(@RequestParam("userId") Integer userId){
        List<PositionInformation> recommendJobs = jobService.getNotInterviewedJobs(userId);
        return AjaxResult.success(recommendJobs);
    }

    @GetMapping("/updateJob")
    public AjaxResult updateJob(@RequestParam("id") Long id){
        jobService.updateJob(id);
        return AjaxResult.success();
    }

    @GetMapping("/analyseResume")
    public AjaxResult analyseResume(@RequestParam("userId") Integer userId) throws Exception {
        AnalyseResumeDTO analyseResumeDTO = jobService.analyseResume(userId);
        return AjaxResult.success(analyseResumeDTO);
    }

    @GetMapping("/userIsInterviewed")
    public AjaxResult userIsInterviewed(@RequestParam("userId") Integer userId) {
        return AjaxResult.success(jobService.userIsInterviewed(userId));
    }
}
